package com.franklin.ideaplugin.maphelper.resolver.impl.map;

import com.franklin.ideaplugin.api.utils.psi.PsiClassUtils;
import com.franklin.ideaplugin.maphelper.beans.colmember.IColMember;
import com.franklin.ideaplugin.maphelper.col.declaration.IColDeclaration;
import com.franklin.ideaplugin.maphelper.resolver.impl.AbstractMethodCallExpressionColMemberResolver;
import com.franklin.ideaplugin.maphelper.resolver.impl.AbstractNewExpressionColMemberResolver;
import com.franklin.ideaplugin.maphelper.resolver.impl.collection.CollectionMethodCallExpressionColMemberResolver;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;

import java.util.Collection;

/**
 * @author Franklin
 * @since 2024/03/09 11:24
 */
public class MapMethodCallExpressionMemberResolver
        extends AbstractMethodCallExpressionColMemberResolver
        implements IMapMemberResolver {

    public final static MapMethodCallExpressionMemberResolver INSTANCE = new MapMethodCallExpressionMemberResolver();

    @Override
    public boolean supports(IColDeclaration colDeclaration) {
        return super.supports(colDeclaration) || CollectionMethodCallExpressionColMemberResolver.INSTANCE.supports(colDeclaration);
    }

    @Override
    public Collection<IColMember> resolveColMembers(PsiElement psiExpression, IColDeclaration colDeclaration) {
        if (CollectionMapMemberResolver.INSTANCE.supports(colDeclaration)){
            return CollectionMapMemberResolver.INSTANCE.resolveColMembers(psiExpression, colDeclaration);
        }
        if (CollectionGetMapMemberResolver.INSTANCE.supports(colDeclaration)){
            return CollectionGetMapMemberResolver.INSTANCE.resolveColMembers(psiExpression, colDeclaration);
        }
        return super.resolveColMembers(psiExpression, colDeclaration);
    }

    @Override
    protected boolean isTargetClass(PsiClass psiClass) {
        return PsiClassUtils.isJavaMapClass(psiClass);
    }

    @Override
    protected AbstractNewExpressionColMemberResolver getNewExpressionColMemberResolver() {
        return MapNewExpressionMemberResolver.INSTANCE;
    }

}
